package view;

import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;

import model.State;

/**
 * Class to create a login action.
 * @author Sarah George
 * @version Autumn 2012
 */
@SuppressWarnings("serial")
public class LoginAction extends AbstractAction {
	
	/**
	 * Field to old the current state of the system.
	 */
	private State my_state;
	
	/**
	 * Field to hold the login JFrame.
	 */
	private JFrame my_frame;
	
	/**
	 * Constructor for a Login Action.
	 * @param the_state the current state of the system.
	 * @param the_frame the login JFrame.
	 */
	public LoginAction(State the_state, JFrame the_frame) {
		super("Login");
	    putValue(Action.MNEMONIC_KEY, KeyEvent.VK_L);
	    putValue(Action.SELECTED_KEY, true);
	    my_state = the_state;
	    my_frame = the_frame;
	}

	/**
	 * Method to login by creating a GUIView and disposing the Login Frame.
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (my_state.loginValid()) {
			new GUIView(my_state).start();
			my_frame.dispose();
		}
	}
}//End class login action.